import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/values/MyColors.dart';
import 'package:flutter_app/widget/custom_app_bar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'unit_select_logic.dart';

/**
 * @Description: 单位选择
 * @Author: 下雨了
 * @CreateDate: 2022年12月1日 15:21:01
 * @UpdateUser: 更新者
 * @UpdateDate:  2022年12月1日 15:21:03
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
///
class UnitSelectPage extends StatefulWidget {
  final String title;

  const UnitSelectPage({Key? key, required this.title}) : super(key: key);

  @override
  _UnitSelectPageState createState() => _UnitSelectPageState();
}

class _UnitSelectPageState extends State<UnitSelectPage> {
  final logic = Get.put(UnitSelectLogic());
  final state = Get.find<UnitSelectLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MyColors.FFF1F1F1,
      appBar: MyAppBar(context, title: widget.title),
      body: Container(
        padding: EdgeInsets.fromLTRB(16.r, 16.r, 16.r, 16.r),
        child: ListView.builder(
          physics: NeverScrollableScrollPhysics(),
          itemCount: state.list.length,
          itemBuilder: (BuildContext context, int index) {
            return BrnCheckbox(
              radioIndex: index,
              // disable: index == 2,
              // widget 在是否在选择 icon 的右边，false 就在左边
              childOnRight: true,
              iconPadding: EdgeInsets.only(right: 16.r, top: 16.r, bottom: 16.r),
              child: Padding(
                padding: EdgeInsets.only(left: 0),
                child: Text("${state.list[index]}", style: TextStyle(color: MyColors.FF666666, fontSize: 13.sp,),             ),
              ),
              onValueChangedAtIndex: (index, value) {
                if (value) {
                  BrnToast.show("第$index项被选中", context);
                } else {
                  BrnToast.show("第$index项取消选中", context);
                }
              },
            );
          },
        ),
      ),
      bottomNavigationBar: Container(
        decoration: BoxDecoration(
            boxShadow: [BoxShadow(
              color: Color(0x1a000000),
              blurRadius: 6.67.r,
              spreadRadius: 0.05.r,
            )],
            shape: BoxShape.rectangle,
            color: Colors.white
        ),
        padding: EdgeInsets.fromLTRB(16.r, 5.r, 16.r, 5.r),
        child: SafeArea(
          child: SizedBox(
            height: 40.r,
            child: TextButton(
              style: TextButton.styleFrom(
                backgroundColor: MyColors.FF2763B9,
                padding: EdgeInsets.all(0),
              ),
              child: Text("确定", style: TextStyle(color: MyColors.FFFFFFFF, fontSize: 14.sp, fontWeight: FontWeight.w600),),
              onPressed: null,
            ),
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<UnitSelectLogic>();
    super.dispose();
  }
}
